package fixtures;

import Controllers.ClientController;
import Controllers.LoginController;
import Controllers.RegisterClientController;
import Controllers.ServerController;
import Entities.ClientEntity;
import Entities.RegisterClientEntity;
import Entities.ServerEntity;
import GUI.ClientGUI;
import GUI.RegisterClientGUI;
import GUI.ServerGUI;
import fit.ActionFixture;

public class RegisterClient extends ActionFixture {
	private ServerController serverController;
	private ClientController clientController;
	private RegisterClientController regClientController;
	private RegisterClientGUI regClientGUI;
	private RegisterClientEntity regClientEntity;
//	private LoginController loginController;
	public RegisterClient()
	{
		
		ServerGUI serverGui=new ServerGUI();
		ServerEntity serverEnt= new ServerEntity();
		serverController=new ServerController(serverGui,serverEnt);
		
		/*if(!serverController.autoStartServer(4555, "root", "root"))
		{
			System.out.println("Server is already running");
		}*/
		ClientGUI clientGui=new ClientGUI();
		ClientEntity clientEntity=new ClientEntity();
		clientController=new ClientController(clientGui,clientEntity);
		//clientController.autoConnectToServer("localhost", 4555);

		serverGui.getBtnConnect().doClick();
		clientGui.getBtnConnect().doClick();
		
		regClientGUI=new RegisterClientGUI();
		regClientEntity = new RegisterClientEntity();
		regClientController=new RegisterClientController(regClientGUI, regClientEntity);

		
		
	}
	
	public void clickButton()
	{
		try{
		regClientGUI.getBtnRegister().doClick();
		Thread.sleep(1000);
		}
		catch(Exception e){}
	}

	public void setUid(String uid) {
		regClientGUI.getUidTf().setText(uid);
	}
	public void setPassword(String password)
	{
		regClientGUI.getPassTf().setText(password);
	}
	public void setName(String name)
	{
		regClientGUI.getNameTf().setText(name);
	}
	public void setLivingArea(String livingArea)
	{
		regClientGUI.getLaCb().setSelectedItem(livingArea);
	}
	public void setDateOfBirth(String dob)
	{
		regClientGUI.getDobTf().setText(dob);
	}
	public void setPhoneNumber(String phoneNumber)
	{
		regClientGUI.getPhoneTf().setText(phoneNumber);
	}
	public void setEmail(String email)
	{
		regClientGUI.getEmailTf().setText(email);
	}
	public boolean validateInput()
	{
		if(regClientController.validateInput())
			return true;
		return false;
	}
	public boolean isValidDate()
	{
		if(regClientController.isValidDate(regClientGUI.getDobTf().getText()))
			return true;
		return false;
	}
}
